import axios from 'axios';
// console.log(axios, 'axios');
import website from '@/config/website';

// NProgress 配置
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
NProgress.configure({ showSpinner: false });

let baseURL = process.env.VUE_APP_BASEURL;
console.log(process.env.VUE_APP_BASEURL, 'process.env.VUE_APP_BASEURL');
//生产环境 修改基本请求地址
// if (process.env.NODE_ENV == 'production') {
//   baseURL = process.env.REN_NING_BASEURL;
// }
//跨域请求，允许保存cookie

axios.defaults.withCredentials = true;
axios.defaults.validateStatus = function(status) {
  return status >= 200 && status <= 500;
};
//创建实例
const mainInstance = axios.create({ baseURL, timeout: 60000 });

//http request拦截
mainInstance.interceptors.request.use(
  (config) => {
    console.log(config, 'config');
    //开启 progress bar
    // NProgress.start();
    // const meta = config.meta || {};
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
//http response 拦截
mainInstance.interceptors.response.use(
  (res) => {
    //关闭 progress bar
    NProgress.done();
    return res;
  },
  (error) => {
    NProgress.done();
    return Promise.reject(new Error(error));
  }
);
export default mainInstance;
